package MULE.Model.Panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

import MULE.Model.EstablishmentSign;
import MULE.Model.LandOffice;
import MULE.Model.Logic.PubLogic;
import MULE.Model.Logic.TownLogic;

/**
 * Panel that displays an overview of the Town and its establishments.
 * 
 * @author jstep
 */
public class TownPanel extends JPanel {

	private final int SIGN_MARGIN = 3;
	private JButton storeButton, pubButton, landOfficeButton,
			assayOfficeButton, exitButton;

	/**
	 * Creates a new TownPanel.
	 */
	public TownPanel(Dimension panelSize) {
		// Initialize panel.
		this.setPreferredSize(panelSize);
		this.setBackground(Color.WHITE);
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		// TODO Add town graphic to left side of panel.
		// ImageIcon townIcon = new ImageIcon();

		// Store entrance.
		this.add(Box.createRigidArea(new Dimension(0, SIGN_MARGIN)));
		storeButton = new EstablishmentSign("Store", Color.WHITE, new Color(
				153, 0, 0));
		storeButton.setAlignmentX(RIGHT_ALIGNMENT);
		String storeCommand = TownLogic.ActionCommand.ENTER_STORE.toString();
		storeButton.setActionCommand(storeCommand);
		this.add(storeButton);
		this.add(Box.createRigidArea(new Dimension(0, SIGN_MARGIN)));
		// Pub entrance.
		pubButton = new EstablishmentSign("Pub", Color.WHITE, new Color(13, 87,
				0));
		pubButton.setAlignmentX(RIGHT_ALIGNMENT);
		String pubCommand = PubLogic.ActionCommand.ENTER_PUB.toString();
		pubButton.setActionCommand(pubCommand);
		this.add(pubButton);
		this.add(Box.createRigidArea(new Dimension(0, SIGN_MARGIN)));
		// Land Office entrance.
		landOfficeButton = new EstablishmentSign("Land Office", Color.WHITE,
				new Color(0, 48, 87));
		landOfficeButton.setAlignmentX(RIGHT_ALIGNMENT);
		String landCommand = LandOffice.ActionCommand.ENTER_LAND_OFFICE
				.toString();
		landOfficeButton.setActionCommand(landCommand);
		this.add(landOfficeButton);
		this.add(Box.createRigidArea(new Dimension(0, SIGN_MARGIN)));
		// Assay Office entrance.
		assayOfficeButton = new EstablishmentSign("Assay Office",
				Color.DARK_GRAY, Color.GRAY);
		assayOfficeButton.setAlignmentX(RIGHT_ALIGNMENT);
		String assayCommand = TownLogic.ActionCommand.ENTER_ASSAY_OFFICE
				.toString();
		assayOfficeButton.setActionCommand(assayCommand);
		this.add(assayOfficeButton);
		this.add(Box.createRigidArea(new Dimension(0, SIGN_MARGIN)));
		// Add exit button.
		exitButton = new EstablishmentSign("Exit Town", Color.WHITE,
				Color.DARK_GRAY);
		exitButton.setAlignmentX(RIGHT_ALIGNMENT);
		String exitCommand = TownLogic.ActionCommand.EXIT_TOWN.toString();
		exitButton.setActionCommand(exitCommand);
		this.add(exitButton);
	}

	/**
	 * Adds an action listener to the panel's exit button.
	 * 
	 * @param listener
	 *            The exit button's listener.
	 */
	public void addExitListener(ActionListener listener) {
		exitButton.addActionListener(listener);
	}

	/**
	 * Adds an action listener to the panel's land office button.
	 * 
	 * @param listener
	 *            The land office button's listener.
	 */
	public void addLandOfficeEntranceListener(ActionListener listener) {
		landOfficeButton.addActionListener(listener);
	}

	/**
	 * Adds an action listener to the panel's pub button.
	 * 
	 * @param listener
	 *            The pub button's listener.
	 */
	public void addPubEntranceListener(ActionListener listener) {
		pubButton.addActionListener(listener);
	}

	/**
	 * Adds an action listener to the panel's store button.
	 * 
	 * @param listener
	 *            The store button's listener.
	 */
	public void addStoreEntranceListener(ActionListener listener) {
		storeButton.addActionListener(listener);
	}
}
